package jwt

import (
	"context"
	"fmt"

	"server_1.0/api/internal/svc"
	"server_1.0/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type DeleteJwtLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewDeleteJwtLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteJwtLogic {
	return &DeleteJwtLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *DeleteJwtLogic) DeleteJwt() (resp *types.PostReps, err error) {
	id := fmt.Sprintf("%v", l.ctx.Value("userId"))
	l.svcCtx.Redis.Del("loginUserId:" + id)
	l.svcCtx.Redis.Do("srem", "loginStatus", id)
	return &types.PostReps{
		Code: 200,
		Msg:  "登出成功",
	}, nil
}
